<?php
/**
 * depart.class.php 部门类
 *
 *
 */
include_once dirname(dirname(__FILE__)).'/database.class.php';

class depart extends database {

    protected $table = 'depart';

    protected $all = '*';

    protected $del = "del='1'";

    protected $field = 'd_name';

    /**
     * 构造函数
     * 继承父类构造函数
     */
    public function __construct() {
        parent::__construct();
    }

    /**
     * 查找是否存在
     * @param $info                  查询的信息
     * @param $sign                  查询的字段
     * @return
     */
    public function select_depart_exist($info,$sign) {
        $where = $sign.' = "'.$info.'" AND '.$this->del;
        $res = parent::select_exist($this->all,$this->table,$where);
        return $res;
    }

    /**
     * 增加部门
     * @param $dname   部门名
     * @return boolean    返回值为布尔型
     */
    public function add_depart($dname) {
        if($dname == '') {
            return false;
        }
        $data = array('d_name'=>$dname,'del'=>'1');
        return parent::insert($data,$this->table);
    }

    /**
     * 获取单个部门信息
     * @param $dingo            查询信息
     * @param $field            查询字段
     * @param $limit            限制语句
     * @return
     */
    public function get_one_depart($dingo, $field, $limit='') {
        $where = $field.'="'.$dingo.'" AND '.$this->del;
        $info = parent::get_one($this->all,$this->table,$where,$limit);
        return $info;
    }

    /**
     * 获取所有部门信息
     * @param $where            查询条件
     * @param $limit           限制语句
     * @return
     */
    public function get_all_depart($where='',$limit='') {
        $where = $where=='' ? $this->del : $where.' AND '.$this->del;
        $info = parent::select($this->all,$this->table,$where,$limit);
        return $info;
    }

    /**
     * 获取总条数
     * @param $where         查询条件
     * @return
     */
    public function get_count_depart($where) {
        $num = parent::select_count($this->table,$where);
        return $num;
    }

    /**
     * 更新部门信息
     * @param $did          部门id
     * @param $dame        部门名
     * @return
     */
    public function update_depart($did, $dame) {
        $data = array('d_name'=>$dame);
        $where = ' d_id="'.$did.'"';
        $res = parent::update($data,$this->table,$where);
        return $res;
    }

    /**
     * 删除部门信息
     * @param $did        部门id
     * @return
     */
    public function delete_depart($did) {
        $where = ' d_id="'.$did.'"';
        $data='del=0';
        $res = parent::update($data,$this->table,$where);
        return $res;
    }

}


?>